package com.company.book_store.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class jdbcutils {
    static Connection con=null;
    static PreparedStatement pst=null;
    static ResultSet res=null;
    public static Connection getConnection(){
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            con= DriverManager.getConnection("jdbc:mysql://rm-bp175g85od44t118lso.mysql.rds.aliyuncs.com:3306/book_store?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC","wjh","Wjh1762291885");
            //pst=con.prepareStatement(sql);
            //ResultSet res=pst.executeQuery();
            return con;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static void close(Connection con,PreparedStatement pst,ResultSet res){
        try {
            if(res!=null)
            {
                res.close();
            }
            if(pst!=null)
            {
                pst.close();
            }
            if(con!=null)
            {
                con.close();
            }
        } catch (Exception throwables) {
            throwables.printStackTrace();
        }
    }

//    public static void main(String[] args) {
//        System.out.println(jdbcutils.getConnection());
//    }
}
